package com.dragon.modules.yuegou.service.impl.act;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dragon.common.exception.DragonException;
import com.dragon.modules.yuegou.entity.act.AnnualRaffleEntity;
import com.dragon.modules.yuegou.entity.act.OffActivityEntity;
import com.dragon.modules.yuegou.entity.act.OffMemberActivityEntity;
import com.dragon.modules.yuegou.entity.act.OffPrizeEntity;
import com.dragon.modules.yuegou.entity.act.SignInEntity;
import com.dragon.modules.yuegou.enums.act.OffActivityStatus;
import com.dragon.modules.yuegou.enums.act.OffMemberActivityIsPrize;
import com.dragon.modules.yuegou.enums.act.OffPrizeStatus;
import com.dragon.modules.yuegou.enums.code.ActivityCode;
import com.dragon.modules.yuegou.enums.order.OrderType;
import com.dragon.modules.yuegou.mapper.act.OffPrizeMapper;
import com.dragon.modules.yuegou.model.act.ActivityPrizeResult;
import com.dragon.modules.yuegou.model.act.GetMyPrizeListResponse;
import com.dragon.modules.yuegou.model.act.LotteryResultsResponse;
import com.dragon.modules.yuegou.model.act.OffActivity;
import com.dragon.modules.yuegou.model.act.OffMemberActivity;
import com.dragon.modules.yuegou.model.act.OffPrize;
import com.dragon.modules.yuegou.model.order.Goods;
import com.dragon.modules.yuegou.model.order.Order;
import com.dragon.modules.yuegou.query.act.OffMemberActivityQuery;
import com.dragon.modules.yuegou.query.act.OffPrizeQuery;
import com.dragon.modules.yuegou.service.act.AnnualRaffleService;
import com.dragon.modules.yuegou.service.act.OffActivityService;
import com.dragon.modules.yuegou.service.act.OffMemberActivityService;
import com.dragon.modules.yuegou.service.act.OffPrizeService;
import com.dragon.modules.yuegou.service.act.SignInService;
import com.dragon.modules.yuegou.service.busd.DistrictService;
import com.dragon.modules.yuegou.service.order.GoodsService;
import com.dragon.modules.yuegou.service.order.OrderService;
import com.dragon.modules.yuegou.web.Check;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Random;
import java.util.stream.Collectors;

/**
 * 线下抽奖活动奖品表 服务实现
 *
 * @author pbuilder generated
 * @date 2019-11-19 10:57:53
 * @version 2.0
 */
@Slf4j
@CacheConfig(cacheNames = OffPrizeServiceImpl.OFF_PRIZE_LIST)
@Service("actOffPrizeService")
public class OffPrizeServiceImpl
		extends ServiceImpl<OffPrizeMapper, OffPrizeEntity>
		implements OffPrizeService {
	protected static final String OFF_PRIZE_LIST = "off_prize_list";


	@Autowired
	private OffMemberActivityService offMemberActivityService;

	@Autowired
	private OffActivityService offActivityService;

	@Autowired
	private OrderService orderService;

	@Autowired
	private DistrictService districtService;

	@Autowired
	private GoodsService goodsService;

	@Autowired
	private AnnualRaffleService annualRaffleService;

	@Autowired
	private SignInService signInService;

	@Autowired
	private OffPrizeService offPrizeService;
	private Cache offPrizeListCache;

	@Autowired
	public void setoffPrizeListCacheManager(CacheManager cacheManager) {
		this.offPrizeListCache = cacheManager.getCache(OFF_PRIZE_LIST);
	}

	@Override
	@Transactional
	public OffPrize startPrize(String id) {
		Check.notEmpty(id, ActivityCode.PRIZE_ID_NOT_EMPTY.getMessage());
		//查询奖品信息
		OffPrizeEntity entity = getById(id);

		if (entity == null) {
			throw new DragonException(ActivityCode.PRIZE_NOT_EXIST);
		}
		OffPrize prize = new OffPrize(entity);
		//查询活动信息
		OffActivityEntity activityEntity = offActivityService.getById(prize.getActivityId());

		if (activityEntity == null) {
			throw new DragonException(ActivityCode.ACTIVITY_NOT_EXIST);
		}
		OffActivity activity = new OffActivity(activityEntity);
		//判断奖品的状态
		if (!prize.getStatus().equals(OffPrizeStatus.NOT_STARTED)) {
			throw new DragonException(ActivityCode.PRIZE_WON_OR_HAS_ENDED);
		}

		//创建中奖列表
		List<OffMemberActivityEntity> list = new ArrayList<>();

		//查询参与活动人数
		OffMemberActivityQuery memberActivityQuery = new OffMemberActivityQuery();
		memberActivityQuery.setActivityId(prize.getActivityId());
		memberActivityQuery.setIsPrize(OffMemberActivityIsPrize.NOT_WON);

		List<OffMemberActivityEntity> memberActivityEntitiesties = offMemberActivityService.list(memberActivityQuery.toQueryWrapper());

		if (CollectionUtils.isEmpty(memberActivityEntitiesties)) {
			throw new DragonException(ActivityCode.NOT_PARTIC);
		}

		//判断参与人数是否大于奖品数量
		if (memberActivityEntitiesties.size() <= prize.getSum()) {
			list.addAll(memberActivityEntitiesties);
			memberActivityEntitiesties.clear();
		} else {
			Integer sum = prize.getSum();
			while (sum > 0) {
				int random = getRandom(memberActivityEntitiesties.size());
				//添加中奖用户
				list.add(memberActivityEntitiesties.get(random));
				//从参与列表中删除中奖用户
				memberActivityEntitiesties.remove(random);
				sum--;
			}
		}

		//给中奖用户创建订单
		list.forEach(memberActivitie -> placeOrder(memberActivitie, prize, activity));

		//修改奖品状态为已结束
		prize.setStatus(OffPrizeStatus.OVER);
		baseMapper.updateById(prize);

		//判断活动下是否还有未抽奖奖品如果没有把活动抽奖状态置为已结束
		OffPrizeQuery prizeQuery = new OffPrizeQuery();
		prizeQuery.setActivityId(activity.getId());
		prizeQuery.setStatus(OffPrizeStatus.NOT_STARTED);
		prizeQuery.setDel(false);
		Long count = count(prizeQuery.toQueryWrapper());

		if (count == 0) {
			//活动状态设为已结束
			activity.setStatus(OffActivityStatus.OVER);
			offActivityService.updateById(activity);
		}

		//隐藏手机号
		formatMobile(list);

		// 推送开奖消息
		try {
			pushRunLotteryMsg(memberActivityEntitiesties, list, prize.getName(), activity.getBusdId());
		} catch (Exception e) {
			log.error("开奖发送服务通知出现错误=====>{},{}", e.getMessage(), e);
		}

		prize.setMemberActivities(list.stream().map(OffMemberActivity::new).collect(Collectors.toList()));
		return prize;
	}

	@Override
	public void start(String prizeId) {
		Check.notEmpty(prizeId, ActivityCode.PRIZE_ID_NOT_EMPTY.getMessage());
		//查询奖品信息
		OffPrizeEntity prize = getById(prizeId);
		if (prize == null) {
			throw new DragonException(ActivityCode.PRIZE_NOT_EXIST);
		}

		//按顺序开奖
		OffPrizeQuery query = new OffPrizeQuery();
		query.setActivityId(prize.getActivityId());
		query.setStatus(OffPrizeStatus.NOT_STARTED);
		QueryWrapper<OffPrizeEntity> wrapper = query.toQueryWrapper();
		wrapper.orderByAsc(OffPrizeEntity.COL_PRICE);
		List<OffPrizeEntity> prizeList = list(wrapper);
		if (null != prizeList && prizeList.size() > 0) {
			OffPrizeEntity offPrize = prizeList.get(0);
			if (!prizeId.equals(offPrize.getId())) {
				throw new DragonException(ActivityCode.MAKE_SURE_PRIZE_ORDER);
			}
		}

		//通知缓存,停止报名
		annualRaffleService.startActivityCache(prize.getActivityId());

		//通知缓存
		LotteryResultsResponse resultsResponse = new LotteryResultsResponse();
		resultsResponse.setPrizeId(prize.getId());
		resultsResponse.setAllOver(false);
		resultsResponse.setGrade(prize.getGrade());
		resultsResponse.setStart(true);
		resultsResponse.setWinners(null);
		annualRaffleService.cacheResult(prize.getActivityId(), resultsResponse);
	}

	@Override
	public OffPrize startPrize2(String id) {
		Check.notEmpty(id, ActivityCode.PRIZE_ID_NOT_EMPTY.getMessage());
		//查询奖品信息
		OffPrizeEntity entity = getById(id);

		if (entity == null) {
			throw new DragonException(ActivityCode.PRIZE_NOT_EXIST);
		}
		OffPrize prize = new OffPrize(entity);
		//查询活动信息
		OffActivityEntity activity = offActivityService.getById(prize.getActivityId());

		if (activity == null) {
			throw new DragonException(ActivityCode.ACTIVITY_NOT_EXIST);
		}

		//判断奖品的状态
		if (!prize.getStatus().equals(OffPrizeStatus.NOT_STARTED)) {
			throw new DragonException(ActivityCode.PRIZE_WON_OR_HAS_ENDED);
		}

		//创建中奖列表
		List<OffMemberActivityEntity> list = new ArrayList<>();

		//查询参与活动人数
		OffMemberActivityQuery memberActivityQuery = new OffMemberActivityQuery();
		memberActivityQuery.setActivityId(prize.getActivityId());
		memberActivityQuery.setIsPrize(OffMemberActivityIsPrize.NOT_WON);

		List<OffMemberActivityEntity> tempMemberActivities = offMemberActivityService.list(memberActivityQuery.toQueryWrapper());

		//踢出名单外的人员
		//所有名单内人员
		List<AnnualRaffleEntity> annualRaffleList = annualRaffleService.list();
		HashSet<String> mobileSet = new HashSet<>();
		annualRaffleList.forEach(annualRaffle -> mobileSet.add(annualRaffle.getMobile()));

		//所有签到人员
		List<String> signInMobileSet = new ArrayList<>();
		List<SignInEntity> signInList = signInService.list();
		signInList.forEach(signIn -> signInMobileSet.add(signIn.getMobile()));

		List<OffMemberActivityEntity> memberActivities = new ArrayList<>();
		tempMemberActivities.stream().forEach(memberActivity -> {
			String mobile = memberActivity.getMemberMobile();
			//在名单内且签过到才有机会中奖
			if (mobileSet.contains(mobile) && signInMobileSet.contains(mobile)) {
				memberActivities.add(memberActivity);
			}
		});

		if (CollectionUtils.isEmpty(memberActivities)) {
			throw new DragonException(ActivityCode.NOT_PARTIC);
		}

		//判断参与人数是否大于奖品数量
		if (memberActivities.size() <= prize.getSum()) {
			list.addAll(memberActivities);
			memberActivities.clear();
		} else {
			Integer sum = prize.getSum();
			while (sum > 0) {
				int random = getRandom(memberActivities.size());
				//添加中奖用户
				list.add(memberActivities.get(random));
				//从参与列表中删除中奖用户
				memberActivities.remove(random);
				sum--;
			}
		}

		List<String> prizeMemberList = new ArrayList<>();//中奖会员ID列表
		List<String> memberIdOrderNoList = new ArrayList<>();//会员Id|订单号
		List<String> wonMobileList = new ArrayList<>();//中奖会员手机号列表
		//给中奖用户创建订单
		list.stream().forEach(memberActivitie -> createOrder(prize,activity,memberActivitie,prizeMemberList,memberIdOrderNoList,wonMobileList));

		//修改奖品状态为已结束
		prize.setStatus(OffPrizeStatus.OVER);
		baseMapper.updateById(prize);

		//判断活动下是否还有未抽奖奖品如果没有把活动抽奖状态置为已结束
		OffPrizeQuery prizeQuery = new OffPrizeQuery();
		prizeQuery.setActivityId(activity.getId());
		prizeQuery.setStatus(OffPrizeStatus.NOT_STARTED);
		prizeQuery.setDel(false);
		Long count = count(prizeQuery.toQueryWrapper());

		if (count == 0) {
			//活动状态设为已结束
			activity.setStatus(OffActivityStatus.OVER);
			offActivityService.updateById(activity);
		}

		//隐藏手机号
		formatMobile(list);

		this.pushMessage(prize,activity,memberActivities,list,prizeMemberList,memberIdOrderNoList,wonMobileList);

		prize.setMemberActivities(list.stream().map(OffMemberActivity::new).collect(Collectors.toList()));
		return prize;
	}

	private void createOrder(OffPrize prize,OffActivityEntity activity,OffMemberActivityEntity memberActivitie,
							 List<String> prizeMemberList,List<String> memberIdOrderNoList,List<String> wonMobileList){
		try {
			prizeMemberList.add(memberActivitie.getMemberId());
			String orderNo = placeOrder(memberActivitie, prize, activity);
			String memberIdOrderNo = memberActivitie.getMemberId()+"|"+orderNo;
			memberIdOrderNoList.add(memberIdOrderNo);
			if(StringUtils.isNotBlank(memberActivitie.getMemberMobile())){
				wonMobileList.add(memberActivitie.getMemberMobile());
			}
		} catch (Exception e) {
			log.error("中奖名单数据异常=====>{},{}", e.getMessage(), e);
		}
	}

	private void pushMessage(OffPrize prize,OffActivityEntity activity,List<OffMemberActivityEntity> memberActivities,List<OffMemberActivityEntity> list,
							 List<String> prizeMemberList,List<String> memberIdOrderNoList,List<String> wonMobileList){

		// 推送到缓存
		try {
			pushCache(prize, prizeMemberList);
		} catch (Exception e) {
			log.error("开奖推送到缓存出现错误=====>{},{}", e.getMessage(), e);
		}
		//刷新缓存
		try {
			offPrizeService.freshPrizeResultCache(prize.getActivityId(),prize.getId(),memberIdOrderNoList);
		} catch (Exception e) {
			log.error("开奖刷新缓存出现错误=====>{},{}", e.getMessage(), e);
		}
		// 推送开奖消息
		try {
			pushRunLotteryMsg(memberActivities, list, prize.getName(), activity.getBusdId());
		} catch (Exception e) {
			log.error("开奖发送服务通知出现错误=====>{},{}", e.getMessage(), e);
		}
		// 短信推送开奖消息
		try {
			pushRunLotteryMsg(wonMobileList, activity.getName(), prize.getName());
		} catch (Exception e) {
			log.error("开奖发送短信通知出现错误=====>{},{}", e.getMessage(), e);
		}
	}

	/**
	 * 隐藏手机号
	 */
	private void formatMobile(List<OffMemberActivityEntity> list) {
		list.forEach(memberActivitie -> {
			String mobile = memberActivitie.getMemberMobile();
			if (StringUtils.isNotEmpty(mobile)) {
				memberActivitie.setMemberMobile(mobile.replaceAll("(\\d{3})\\d{4}(\\d{4})", "$1****$2"));
			}
		});
	}

	private void pushCache(OffPrize prize, List<String> wonList) {
		//通知缓存
		OffPrizeQuery isOverQuery = new OffPrizeQuery();
		isOverQuery.setActivityId(prize.getActivityId());
		List<OffPrizeEntity> isOverPrizeList = list(isOverQuery.toQueryWrapper());
		Boolean isOver = true;
		//如果抽奖状态全都是over 则整个抽奖结束
		for (OffPrizeEntity isOverPrize : isOverPrizeList) {
			if (isOverPrize.getId().equals(prize.getId())) continue;//排除当前的
			if (isOverPrize.getStatus() != OffPrizeStatus.OVER) isOver = false;
		}
		LotteryResultsResponse resultsResponse = new LotteryResultsResponse();
		resultsResponse.setPrizeId(prize.getId());
		resultsResponse.setAllOver(isOver);
		resultsResponse.setGrade(prize.getGrade());
		resultsResponse.setStart(false);
		resultsResponse.setWinners(wonList);
		annualRaffleService.cacheResult(prize.getActivityId(), resultsResponse);
	}

	/**
	 * 短信通知中奖
	 * @param wonMobileList
	 * @param activityName
	 * @param prizeName
	 */
	private void pushRunLotteryMsg(List<String> wonMobileList, String activityName, String prizeName) {
		wonMobileList.stream().forEach(s -> sendBySms(s, activityName, prizeName));
	}

	/**
	 * 发送短信
	 *
	 * @param mobile
	 * @param activityName
	 * @param prizeName
	 */
	private void sendBySms(String mobile, String activityName, String prizeName) {
//		Sms sms = SmsTemplate.LOTTERY.builder()
//				.mobile(mobile)
//				.params(activityName, prizeName)
//				.build();
//		smsFactory.service(SmsProvider.YUNTONGXUN).send(sms);
	}

	/**
	 * 推送服务
	 */
	private void pushRunLotteryMsg(List<OffMemberActivityEntity> notWonList, List<OffMemberActivityEntity> wonList, String skuTitle, String busdId) {
		//获取AppId
		String appId = districtService.getAppId(busdId);

		//中奖推送
		wonList.stream().forEach(memberActivitie -> {
			//查询单品Id
			List<Goods> goodsList = goodsService.listByOrder(memberActivitie.getOrderNo());
			if (CollectionUtils.isNotEmpty(goodsList)){
				Goods goods = goodsList.get(0);
//				ActivityOffWonEvent wonEvent = new ActivityOffWonEvent(goods.getId(), memberActivitie.getMemberId(), skuTitle, "已中奖，请尽快咨询服务台领奖。");
//				wonEvent.setAppid(appId);
//				wonEvent.setAppversion("2.0");
//				eventPublisher.publish(wonEvent);
			}

		});

		//未中奖推送
		notWonList.stream().forEach(memberActivitie -> {
//			ActivityOffNotWonEvent notWonEvent = new ActivityOffNotWonEvent(memberActivitie.getMemberId(), skuTitle, "未中奖，可查看商城其他优惠活动~");
//			notWonEvent.setAppid(appId);
//			notWonEvent.setAppversion("2.0");
//			eventPublisher.publish(notWonEvent);
		});
	}

	/**
	 * 随机生成数字
	 */
	private static int getRandom(int max) {
		return new Random().nextInt(max);
	}

	/**
	 * 创建订单
	 */
	private String placeOrder(OffMemberActivityEntity memberActivity, OffPrize prize, OffActivityEntity activity) {
		//创建订单
		Order order = orderService.createNullOrder(prize.getSkuId(), memberActivity.getMemberId(), activity.getBusdId(), OrderType.LOTTERY, true,1);

		//设置会员参与状态为已中奖
		memberActivity.setIsPrize(OffMemberActivityIsPrize.HAS_WON);
		//设置订单号
		memberActivity.setOrderNo(order.getId());
		memberActivity.setPrizeId(prize.getId());
		memberActivity.setGrade(prize.getGrade());
		memberActivity.setSkuId(prize.getSkuId());

		offMemberActivityService.updateById(memberActivity);
		return order.getId();
	}

	@Override
	public List<OffPrize> winningList(String id) {
		Check.notEmpty(id, "活动Id不能为空");
		//查询活动下已开奖的奖品
		OffPrizeQuery prizeQuery = new OffPrizeQuery();
		prizeQuery.setActivityId(id);
		prizeQuery.setStatus(OffPrizeStatus.OVER);
		prizeQuery.setDel(false);
		List<OffPrizeEntity> entities = list(prizeQuery.toQueryWrapper());
		List<OffPrize> prizes = entities.stream().map(OffPrize::new).collect(Collectors.toList());

		//活动奖品中奖信息
		prizes.stream().forEach(prize -> {
			OffMemberActivityQuery memberActivityQuery = new OffMemberActivityQuery();
			memberActivityQuery.setActivityId(id);
			memberActivityQuery.setPrizeId(prize.getId());
			List<OffMemberActivityEntity> list = offMemberActivityService.list(memberActivityQuery.toQueryWrapper());
			//隐藏手机号
			formatMobile(list);
			prize.setMemberActivities(list.stream().map(OffMemberActivity::new).collect(Collectors.toList()));
		});

		return prizes;
	}

	@Override
	public GetMyPrizeListResponse getMyPrizeList(String id, String memberId) {
		Check.notEmpty(id, ActivityCode.ACTIVITY_ID_NOT_EMPTY.getMessage());
		GetMyPrizeListResponse response = new GetMyPrizeListResponse();

		//获取活动信息
		OffActivity offActivity = offActivityService.getActivityByCache(id);
		if (offActivity == null) {
			throw new DragonException(ActivityCode.ACTIVITY_NOT_EXIST);
		}
		response.setOffActivity(offActivity);

		//获取会员参与信息
		boolean isJoin = offMemberActivityService.isJoin(id, memberId);
		response.setJoin(isJoin);

		//中奖人员名单
		List<ActivityPrizeResult>  prizeResultList = getPrizeResult(id);
		List<OffPrize> prizeList = new ArrayList<>();
		boolean isPrize = false;//是否存在即将开奖
		for (ActivityPrizeResult result : prizeResultList) {
			isPrize = this.setResult(result,isPrize,memberId,prizeList);
		}
		response.setList(prizeList);
		return response;
	}

	private Boolean setResult(ActivityPrizeResult result,boolean isPrize,String memberId,List<OffPrize> prizeList){
		OffPrize prize =new OffPrize();
		prize.setGrade(result.getPrizeName());
		if(result.getStatus() == OffPrizeStatus.OVER){
			String memberPrizeStr ="";
			for (String s:result.getList()) {
				if (s.contains(memberId)) {
					memberPrizeStr = s;
					break;
				}
			}
			if (StringUtils.isBlank(memberPrizeStr)) {
				prize.setPrizeStatus(1);//已开奖未中奖
			} else {
				prize.setPrizeStatus(2);//已开奖已中奖
				String[] arr = memberPrizeStr.split("\\|");
				List<Goods> goodsList = goodsService.listByOrder(arr[1]);
				if (CollectionUtils.isNotEmpty(goodsList)) {
					prize.setGoodsId(goodsList.get(0).getId());
				}
			}
		}else{//未开始/正在进行
			this.setPrize(prize,isPrize);
		}
		prizeList.add(prize);
		return isPrize;
	}

	private Boolean setPrize(OffPrize prize,Boolean isPrize){
		if (isPrize) {
			//状态:0未开奖 1:已开奖未中奖 2:已开奖已中奖 3:即奖开奖
			prize.setPrizeStatus(0);
		} else {
			prize.setPrizeStatus(3);
			isPrize = true;
		}
		return isPrize;
	}

	@Override
	public List<ActivityPrizeResult> getPrizeResult(String activityId) {
		List<ActivityPrizeResult> list = offPrizeListCache.get(activityId, List.class);
		if (null == list) {
			list = new ArrayList<>();
			OffPrizeQuery prizeQuery = new OffPrizeQuery();
			prizeQuery.setActivityId(activityId);
			QueryWrapper<OffPrizeEntity> wrapper = prizeQuery.toQueryWrapper();
			wrapper.orderByAsc(OffPrizeEntity.COL_PRICE);
			List<OffPrizeEntity> prizes = list(wrapper);

			for (OffPrizeEntity offPrize:prizes) {
				ActivityPrizeResult result = new ActivityPrizeResult();
				result.setPrice(offPrize.getPrice());
				result.setPrizeId(offPrize.getId());
				result.setPrizeName(offPrize.getGrade());
				result.setStatus(offPrize.getStatus());

				//查询中奖人名单
				OffMemberActivityQuery memberActivityQuery = new OffMemberActivityQuery();
				memberActivityQuery.setActivityId(activityId);
				memberActivityQuery.setPrizeId(offPrize.getId());
				memberActivityQuery.setIsPrize(OffMemberActivityIsPrize.HAS_WON);
				List<OffMemberActivityEntity> prizeList = offMemberActivityService.list(memberActivityQuery.toQueryWrapper());

				List<String> prizeMemberList = new ArrayList<>();
				prizeList.stream().forEach(memberActivity -> prizeMemberList.add(memberActivity.getMemberId()+"|"+memberActivity.getOrderNo()));
				result.setList(prizeMemberList);
				list.add(result);
			}
			offPrizeListCache.put(activityId, list);
		}
		return list;
	}

	@Override
	public void freshPrizeResultCache(String activityId, String prizeId, List<String> wonList) {
		List<ActivityPrizeResult> list = getPrizeResult(activityId);
		list.forEach(prizeResult -> {
			if(prizeResult.getPrizeId().equals(prizeId)){
				prizeResult.setList(wonList);
				prizeResult.setStatus(OffPrizeStatus.OVER);
			}
		});
		offPrizeListCache.put(activityId, list);
	}
}